﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ConsoleAppDemo {
    public class AutoResetEventManage {
        private AutoResetEvent event_1;
        private AutoResetEvent event_2;
        public AutoResetEventManage(AutoResetEvent event_1,
            AutoResetEvent event_2)
        {
            this.event_1 = event_1;
            this.event_2 = event_2;
        }
        public void ThreadProc()
        {
            string name = Thread.CurrentThread.Name;
            Console.WriteLine("{0} waits on AutoResetEvent #1.", name);
            event_1.WaitOne();
            Console.WriteLine("{0} is released from AutoResetEvent #1.", name);

            Console.WriteLine("{0} waits on AutoResetEvent #2.", name);
            event_2.WaitOne();
            Console.WriteLine("{0} is released from AutoResetEvent #2.", name);
            Console.WriteLine("{0} ends.", name);
        }
    }
}
